package com.ebt.m.policy.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.activity.WebBaseActivity;
import com.ebt.m.commons.buscomponent.listview.BaseListView;
import com.ebt.m.commons.buscomponent.listview.ISectionFactory;
import com.ebt.m.data.rxModel.apibean.ProductItemsBean;
import com.ebt.m.policy.presenter.BrandsProductsAllPresenter;
import com.ebt.m.utils.RecyclerViewDivider;

import java.util.List;


/**
 * 该品牌下所有产品
 *
 * @author Damon.Han
 */
public class BrandsProductListAllView extends BaseListView<BrandsProductsAllPresenter> {

    public BrandsProductListAllView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BrandsProductListAllView(Context context) {
        this(context, null);
    }

    public BrandsProductListAllView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mRecyclerView.addItemDecoration(new RecyclerViewDivider(context, LinearLayoutManager.HORIZONTAL, (int) getResources().getDimension(R.dimen.common_divider_dimen), getResources().getColor(R.color.common_divider_color)));
        mRefreshLayout.setRefreshNeeded(false);
    }


    @Override
    protected ISectionFactory createViewFactory() {
        return viewType -> {
            BrandsProductViewItem appsViewItem = new BrandsProductViewItem(getContext());
            return appsViewItem;
        };
    }

    private void gotoWeb(boolean isHideTitle, String title, String url, boolean isHideToolbar) {
        Intent webIntent = new Intent(getContext(), WebBaseActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString(WebBaseActivity.WEB_TYPE_TITLE, isHideTitle ? "" : title);
        bundle.putInt(WebBaseActivity.WEB_TYPE_FRAGMENT, 111);
        bundle.putBoolean(WebBaseActivity.WEB_TYPE_HIDE_TOOLBAR, isHideToolbar);
        bundle.putString(WebBaseActivity.WEB_TYPE_LINK, url);
        webIntent.putExtras(bundle);
        getContext().startActivity(webIntent);
    }

    @Override
    protected BrandsProductsAllPresenter createPresenter() {
        return new BrandsProductsAllPresenter(getContext(), this);
    }

    @Override
    public void loadNext() {

    }

    @Override
    public void update(Object... args) {
        super.update(args);
        List<ProductItemsBean> list = (List<ProductItemsBean>) args[0];
        mPresenter.loadNew(list);
    }


    @Override
    protected View configEmptyView() {
        View emptyContent = LayoutInflater.from(getContext()).inflate(R.layout.layout_product_search_empty, null);
        ImageView imageView = (ImageView) emptyContent.findViewById(R.id.img_empty);
        TextView textView = (TextView) emptyContent.findViewById(R.id.mession_empty);
        imageView.setBackgroundResource(R.drawable.ic_empty_product);
        textView.setText("没有相关产品");
        return emptyContent;
    }

}
